// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in commonUtils.js
// 'starter.controllers' is found in controllers.js
var webserver = 'http://192.168.1.106:8080/eos-default/';
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])


  .run(function ($rootScope, $ionicPlatform,CustomersService) {
    //读取微平台用户数据
/*      cordova.exec(function(msg) {
        var user = eval('('+msg+')');
        $rootScope.userId = user.userId;
        alert(JSON.stringify(user));
        alert($rootScope.userId);
      }, function(e) {console.log("Error: "+e);}, "UsersInfo","getUsersInfo",[]);*/
    CustomersService.getUserInfo(function(userinfo){});

    $ionicPlatform.ready(function () {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        cordova.plugins.Keyboard.disableScroll(true);

      }
      if (window.StatusBar) {
        // org.apache.cordova.statusbar required
        //StatusBar.styleLightContent();
        StatusBar.hide();
        $ionicPlatform.fullScreen();
      }
    });
  })

  .config(function ($stateProvider, $urlRouterProvider) {

    // Ionic uses AngularUI Router which uses the concept of states
    // Learn more here: https://github.com/angular-ui/ui-router
    // Set up the various states which the app can be in.
    // Each state's controller can be found in controllers.js
    $stateProvider

      // setup an abstract state for the tabs directive
      .state('tab', {
        url: '/tab',
        abstract: true,
        templateUrl: 'templates/tabs.html'
      })

      // Each tab has its own nav history stack:

      .state('tab.fav', {
        url: '/favourite',
        views: {
          'tab-favourite': {
            templateUrl: 'templates/tab-favourite.html',
            controller: 'CusCtrl'
          }
        }
      })

      .state('tab.cus', {
        url: '/customers',
        views: {
          'tab-customers': {
            templateUrl: 'templates/tab-customers.html',
            controller: 'CusCtrl'
          }
        }
      })
      .state('tab.follow', {
        url: '/follow',
        views: {
          'tab-follow': {
            templateUrl: 'templates/tab-follow.html',
            controller: 'tabfollowCtr'
          }
        }
      })
      .state('tab.info', {
        url: '/info',
        views: {
          'tab-info': {
            templateUrl: 'templates/tab-info.html',
            controller: 'tabinfoCtrl'
          }
        }
      })
      .state('customer', {
        url: '/customer',
        templateUrl: 'templates/customer.html',
        controller: 'CustomerCtrl'
      })
      .state('followDetial', {
        url: '/followDetial?cid?cname#foot',
        templateUrl: 'templates/followDetial.html',
        controller: 'followDetialCtr'
      })
      .state('customer-edit', {
        url: '/customer/edit',
        templateUrl: 'templates/customer_edit.html',
        controller: 'CustomerEditCtrl'
      })
      .state('contacts', {
        url: '/contacts?action',
        templateUrl: 'templates/contacts.html',
        controller: 'contactsCtr'
      })
      .state('Orgs', {
        url: '/Orgs',
        templateUrl: 'templates/Orgs.html',
        controller: 'OrgCtr'
      })
      .state('editCard', {
        url: '/editCard',
        templateUrl: 'templates/edit_card.html',
        controller: 'EditCardCtrl'
      })
      .state('selectUser', {
        url: '/selectUser',
        templateUrl: 'templates/single_user.html',
        controller: 'SingleUserCtrl'
      })
      .state('location', {
        url: '/location',
        templateUrl: 'templates/location.html',
        controller: 'LocationCtrl'
      });

    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/tab/customers');

  })
  .config(function ($ionicConfigProvider) {
    $ionicConfigProvider.tabs.position("bottom");
    $ionicConfigProvider.tabs.style("standard");
  })
  //.config(function ($cordovaInAppBrowserProvider) {
  //  var defaultOptions = {
  //    location: 'no',
  //    clearcache: 'no',
  //    toolbar: 'no'
  //  };
  //
  //  document.addEventListener(function () {
  //
  //    $cordovaInAppBrowserProvider.setDefaultOptions(options)
  //
  //  }, false);
  //})
;
